# MySQL到KWDB迁移工具 Docker镜像
FROM python:3.8-slim

# 设置标签
LABEL maintainer="MySQL-to-KWDB Migration Tool" \
      version="1.0.0" \
      description="High-performance MySQL to KWDB migration tool with stability and monitoring features"

# 设置环境变量
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    MIGRATION_LOG_LEVEL=INFO \
    MIGRATION_MAX_WORKERS=4

# 设置工作目录
WORKDIR /app

# 安装系统依赖和监控工具
RUN apt-get update && apt-get install -y \
    gcc \
    g++ \
    curl \
    wget \
    htop \
    procps \
    net-tools \
    && rm -rf /var/lib/apt/lists/*

# 复制依赖文件
COPY requirements.txt .
COPY setup.py .

# 安装Python依赖
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir -e .

# 复制应用代码
COPY src/ ./src/
COPY config/ ./config/
COPY scripts/ ./scripts/
COPY migrate.py .
COPY README.md .

# 创建必要目录
RUN mkdir -p /app/logs /app/data /app/output

# 设置权限
RUN chmod +x scripts/*.sh

# 创建非root用户
RUN useradd -m -u 1000 migrator && \
    chown -R migrator:migrator /app
USER migrator

# 添加健康检查脚本
COPY scripts/health_check.sh ./scripts/
RUN chmod +x scripts/health_check.sh

# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD ./scripts/health_check.sh || exit 1

# 暴露端口（API服务）
EXPOSE 8080

# 添加启动脚本
COPY scripts/docker_entrypoint.sh ./
RUN chmod +x docker_entrypoint.sh

# 默认命令
ENTRYPOINT ["./docker_entrypoint.sh"]
CMD ["--help"]

